import axios from "axios";

const ajax = axios.create({
    baseURL: '/api',
    headers: {
        "Content-Type": "application/json;charset=UTF-8"
    }
});

ajax.interceptors.request.use((request) => {

    return request
});

ajax.interceptors.response.use(function (response) {
    return response.data;
}, function (error) {
    console.log(error);
    if (!error || !error.response) {
        throw {
            "code": 500,
            "message": "服务器异常，请稍后再试"
        };
    }
    let status = error.response.status;
    if (status === 401) {

    } else if (status === 500) {
        throw {
            "code": 500,
            "message": "服务器异常，请稍后再试"
        };
    } else {
        throw error.response.data;
    }
});
export default ajax;
